package com.wanbangee.marksystem.controller;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.wanbangee.marksystem.entities.USchool;
import com.wanbangee.marksystem.service.USchoolService;

@RestController
@RequestMapping("schoolManage")
public class USchoolController {
	@Autowired
	private USchoolService getSchoolInformation;
	
	@RequestMapping(value="selectSchoolBySchId", method=RequestMethod.GET)
	public Map<String, Object> selectSchoolBySchId(int schId){
		Map<String, Object> map = new HashMap<String, Object>();
		USchool school = getSchoolInformation.getSchoolInformationBySchIdService(schId);
		map.put("code", 1001);
		map.put("school", school);
		map.put("message", "接口成功");
		return map;
	}
	
	@RequestMapping(value="selectSchoolBypaging", method=RequestMethod.GET)
	public Map<String, Object> selectSchoolBypaging(Integer paging,Integer size){
		Map<String, Object> map = new HashMap<String, Object>();
		List<USchool> schools = getSchoolInformation.selectSchoolBypaging(paging, size);
		Integer total=getSchoolInformation.selectSchool();
		map.put("code", 1001);
		map.put("school", schools);
		map.put("total",total);
		map.put("message", "接口成功");
		return map;
	}
	
	@PostMapping("insertSchool")
	public Map<String, Object> insertSchool(USchool uSchool) {
		Map<String, Object> map = new HashMap<>();
		int insertTime = getSchoolInformation.insertSchoolInformation(uSchool);
		if(insertTime > 0) {
			map.put("code", 1001);
			map.put("message", "接口成功");
		}
		return map;
	}
	@PutMapping("updateSchool")
	public Map<String, Object> updateSchool( USchool uSchool) {
		System.out.println(uSchool);
		Map<String, Object> map = new HashMap<>();
		int updateState = getSchoolInformation.updateSchool(uSchool);
		if(updateState > 0) {
			map.put("code", 1001);
			map.put("message", "接口成功");
		}
		return map;
	}
	
	@GetMapping("selectSchoolByschNmAndLevel")
	public  Map<String, Object> selectSchoolByschNmAndLevel(String schNm, int schLevel){
		Map<String, Object> map = new HashMap<>();
		List<USchool> lists = getSchoolInformation.selectSchoolByschNmAndLevel(schNm, schLevel);
		Integer total=getSchoolInformation.selectSchool();
		map.put("code", 1001);
		map.put("lists", lists);
		map.put("total",lists.size());
		map.put("message", "接口成功");
		return map;
	}
	
	@PutMapping("deleteSchool")
	public Map<String, Object> deleteSchool(int schId) {
		Map<String, Object> map = new HashMap<>();
		int deleteState = getSchoolInformation.deleteSchool(schId);
		if(deleteState > 0) {
			map.put("code", 1001);
			map.put("message", "接口成功");
		}
		return map;
	}
	@PutMapping("updateSchState")
	public Map<String, Object> updateSchState(int schId, int schState) {
		Map<String, Object> map = new HashMap<>();
		int updateSchState = this.getSchoolInformation.updateSchState(schId, schState);
		if(updateSchState > 0) {
			map.put("code", 1001);
			map.put("message", "接口成功");
		}
		return map;
	}

	
}
